<%-- Copyright (c) 2002 BroadVision, Inc. All rights reserved              --%>
<%-- The product described in this manual may be protected by one or more  --%>
<%-- U.S. and International patents. The BroadVision One-To-One software   --%>
<%-- is covered by U.S. patent 5,710,887.                                  --%>
<%--                                                                       --%>
<%-- TRADEMARKS: BroadVision and the BroadVision logo are registered       --%>
<%-- trademarks, and BroadVision One-To-One is a trademark of BroadVision, --%>
<%-- Inc. IONA and Orbix are trademarks of IONA Technologies, Ltd. RSA,    --%>
<%-- MD5, and RC2 are trademarks of RSA Data Security, Inc. All other      --%>
<%-- trademarks, service marks, and trade names belong to their respective --%>
<%-- owners. BroadVision, Inc. disclaims any proprietary interest in the   --%>
<%-- marks and names of others.                                            --%>
<%--                                                                       --%>

<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic"%>
<%@ taglib uri="/WEB-INF/bv-html.tld" prefix="bvhtml"%>
<%@ taglib uri="/WEB-INF/c.tld" prefix="c" %>

<%@include file="/mt/common/pickerPopupHelper.jsp" %>

<SCRIPT>
function checkMaxLength(taText,len)
{
    if (taText.value.length > len)
        taText.blur();
}

function checkNumberOnly(e) {
    var charCode = (navigator.appName == "Netscape") ? e.which : e.keyCode;
    if (charCode > 31 && (charCode < 48 || charCode > 57)) {
      return false;
    }
    else {
      return true;
    }
}

function doAction(action, myform)
{
    myform.action='<html:rewrite page="'+action+'" />';
    myform.submit();
    return true;
}

function doReset(myform)
{
    location = '<html:rewrite page="/em/ruleset/ruleSetNew.do" />';
    return false;
}

function doCancel(myform)
{
    location = '<html:rewrite page="/em/ruleset/ruleSetNewSearch.do" />';
    return false;
}

function validateForm(myform) 
{   
    if( validate(myform) == false)
      return false;

    if( myform.contentType.options[myform.contentType.selectedIndex].value == "-1") {
          alert(" <bean:message bundle="em" key="emarketing.ruleset.error.rulesetcontenttype" /> ");
          myform.contentType.focus();
          return false;
    }
    
    var val;
    for (i=0;i<myform.defaultAction.length;i++)
    {
    	if (myform.defaultAction[i].checked)
    	{
    	   val = myform.defaultAction[i].value;
    	}
    }
     
    if( val == "1" && myform.itemKey.value == "") {
          alert(" <bean:message bundle="em" key="emarketing.ruleset.ruleSetEdit.javaScript.alert.selectItem" /> ");
          return false;
    }     
     
    if( val == "2" && myform.categoryPath.value == "") {
          alert(" <bean:message bundle="em" key="emarketing.ruleset.ruleSetEdit.javaScript.alert.selectCategory" /> ");
          return false;
    }     
    return true;
}

function onSelectContent( selectedOids, selectedNames) {
  theForm = document.emRuleSetForm;
  theForm.itemKey.value = selectedNames.toString();
  theForm.contentOid.value = parseInt(selectedOids.toString());
}

function onSelectCategory( selectedOids, selectedNames) {
  theForm = document.emRuleSetForm;
  theForm.categoryPath.value = selectedNames.toString();
  theForm.categoryOid.value = parseInt(selectedOids.toString());
}


function onClickDoNothing( form ) {

  form.browseItem.disabled=true;
  form.browseCategory.disabled=true;
  form.includeSubCategory.disabled=true;
  form.numItems.disabled=true;
  
  form.itemKey.value="";
  form.categoryPath.value="";
  form.numItems.value="1";
  form.includeSubCategory.checked=false;
}

function onClickItemAction( form ) {

  form.browseItem.disabled=false;
  
  form.browseCategory.disabled=true;
 
  form.numItems.disabled=true;
  form.numItems.value="1";
  
  form.includeSubCategory.disabled=true;
  form.includeSubCategory.checked=false;
  
  form.categoryPath.value="";

}

function onClickCategoryAction( form ) {

  form.browseItem.disabled=true;

  form.browseCategory.disabled=false;
  form.includeSubCategory.disabled=false;
  form.numItems.disabled=false;
  
  form.itemKey.value="";
}

</SCRIPT>

<html:javascript formName="emRuleSetForm" method="validate" />

<table width="100%" border="0" cellspacing="0" cellpadding="0"
	class="zoneFive">
	<tr>
		<td valign="top" width="100%">
		<div class="pageTitle">
			<bean:message bundle="em" key="emarketing.ruleSet.ruleSetSummaryNew.pageTitle" /> <br>
		</div>
		<div class="errorMessage"><html:errors bundle="em"/></div>
		<div><%@include file="/mc/common/pagetab.jsp"%></div>
		<div class="pageInstructions">
			<bean:message bundle="em" key="emarketing.ruleSet.ruleSetSummaryNew.pageInstruction" />
		</div>
		<div class="pageSubtitle">
			<bean:message bundle="em" key="emarketing.ruleSet.ruleSetSummaryNew.header" />
		</div>

		<html:form action="/em/ruleset/ruleSetCreate.do" focus="name" onsubmit="return validateForm(this);">
		
			<table width="100%" border="0" cellspacing="0" cellpadding="0" class="labelForm">
				<tr>
					<td valign="top" wrap class="label" width="30%">
						<bean:message bundle="em" key="emarketing.ruleset.ruleSetSearch.lable.ruleSetName" />*:
					</td>
					<td valign="top" wrap class="labelField" width="70%">
						<html:messages id="nameError" property="name" bundle="em" />
						<c:if test="${not empty nameError}">
						              <span class="errorMessage">
						                <c:out value="${nameError}" />
						              </span>
						              <br>
            					</c:if>
						<html:text property="name" size="30" maxlength="80" />
					</td>
				</tr>
				<tr>
					<td valign="top" wrap class="label" width="30%">
						<bean:message bundle="em" key="emarketing.ruleSet.ruleSetSummary.lable.offerContentType" />*:
					</td>
					<td valign="top" wrap class="labelField" width="70%">
						<html:messages id="contentTypeError" property="contentType" bundle="em" />
						<c:if test="${not empty contentTypeError}">
							<span class="errorMessage">
							   <c:out value="${contentTypeError}" />
							</span>
							<br>
            					</c:if>						
						<bean:define id="types" name="emRuleSetForm" property="contentTypeList"
						type="java.util.Collection" /> 
						<html:select name="emRuleSetForm" property="contentType">
							<option value=""><bean:message bundle="em" key="em.option.select" /></option>
							<html:options collection="types" property="typeId" labelProperty="friendlyName" />
						</html:select>
					</td>
				</tr>
				<tr>
					<td valign="top" wrap class="label" width="30%">
						<bean:message bundle="em" key="emarketing.ruleset.text.description" />:
					</td>
					<td valign="top" wrap class="labelField" width="70%">
						<html:messages id="descriptionError" property="description" bundle="em" />
						<c:if test="${not empty descriptionError}">
							<span class="errorMessage">
								<c:out value="${descriptionError}" />
							</span>
							<br>
            					</c:if>						
						<html:textarea property="description" onkeypress="checkMaxLength(this,255)"
						rows="3" cols="40" />
					</td>
				</tr>
				<tr>
					<td valign="top" wrap class="label" width="30%">
						<bean:message bundle="em" key="em.label.status" />:
					</td>
					<td valign="top" wrap class="labelField" width="70%">
					    	<html:radio property="status" value="1"/>
					    	<bean:message bundle="em" key="em.label.online"/>
					    	<html:radio property="status" value="0"/>
					    	<bean:message bundle="em" key="em.label.offline"/>
					</td>
				</tr>
				<tr>
					<td valign="top" wrap class="label" width="30%">
						<bean:message bundle="em" key="emarketing.ruleset.ruleSetEdit.lable.evaluationMethod" />*:
					</td>
					<td valign="top" wrap class="labelField" width="70%">
						<html:messages id="evalMethodError" property="evalMethod" bundle="em" />
						<c:if test="${not empty evalMethodError}">
							<span class="errorMessage">
							   <c:out value="${evalMethodError}" />
							</span>
							<br>
            					</c:if>
						<html:select property="evalMethod">
						<option value=""><bean:message bundle="em" key="em.option.select" /></option>
						<option value="ALL"><bean:message bundle="em"
							key="emarketing.ruleset.ruleSetEdit.lable.evaluateall" /></option>
						<option value="FIRST"><bean:message bundle="em"
							key="emarketing.ruleset.ruleSetEdit.lable.evaluatefirst" /></option>
						</html:select>
					</td>
				</tr>
				<tr>
				  <td valign="top" wrap class="label" width="30%">
				    <bean:message bundle="em" key="emarketing.ruleset.ruleSetEdit.header.defaultAction" />*:
				  </td>
				  <td valign="top" class="labelField" width="70%">
				    <html:radio property="defaultAction" value="0" onclick="onClickDoNothing(this.form) "/>
				    <bean:message bundle="em" key="emarketing.ruleset.ruleSetEdit.radio.value.doNothing" />
				  </td>
				</tr>
				<tr>
				 <td valign="top" wrap class="label" width="30%">&nbsp;</td>
			  	 <td valign="top" class="labelField" width="70%">
					<html:radio property="defaultAction" value="1" onclick="onClickItemAction(this.form)" />
					<bean:message bundle="em" key="emarketing.ruleset.ruleSetEdit.radio.value.pickOneItem" />
					<br>
					<html:text size="30" property="itemKey" disabled="true"/>
					<input type="button" name="browseItem"
							value="<bean:message bundle="em" key="button.browseItem"/>"
							class="inputButton" onclick="doPickerPopupAction('<html:rewrite page="/mt/pickerPopup.do"/>', 'onSelectContent', this.form.contentType.value , null, null, null, true, false, true);" disabled="true" /> 
			         </td>
					<html:hidden property="contentOid"/>
				</tr>
				<tr>
				  <td valign="top" wrap class="label" width="30%">&nbsp;</td>
				  <td valign="top" class="labelField" width="70%">
					<html:radio property="defaultAction" value="2" onclick="onClickCategoryAction(this.form)" />
						<bean:message bundle="em" key="emarketing.ruleset.ruleSetEdit.radio.value.pickCategory" />
					<br>
						<html:text size="30" property="categoryPath" disabled="true"/>					
						<input type="button" name="browseCategory"
							value="<bean:message bundle="em" key="button.browseCategory"/>"
							class="inputButton" onclick="doPickerPopupAction('<html:rewrite page="/mt/categoryPickerPopup.do"/>', 'onSelectCategory', this.form.contentType.value , null, null, null, true, false, false );" disabled="true" />
					<br>
						<html:messages id="numItemsError" property="numItems" bundle="em" />
						<c:if test="${not empty numItemsError}">
							<span class="errorMessage">
							   <c:out value="${numItemsError}" />
							</span>
            					</c:if>			
				        	<bean:message bundle="em" key="emarketing.ruleset.text.numContents" />*:
					      <html:text size="3" maxlength="3" property="numItems" disabled="true" onkeypress="return checkNumberOnly(event)" />	
				        	
				        <br>	
				        	<html:checkbox property="includeSubCategory" disabled="true" />
						<bean:message bundle="em" key="emarketing.ruleset.text.includeSubCategories" />
                                    <html:hidden property="categoryOid"/>
					</td>
				</tr>
			</table>
			<div class="pageButtonWrap" align="right">
				<input	type="button" name="resetButton" class="inputButton"
						value="<bean:message bundle="em" key="button.reset"/>"
						onClick="doReset(this.form);">
				&nbsp;&nbsp;
				<input type="button" name="cancelButton" class="inputButton"
						value="<bean:message bundle="em" key="button.cancel"/>"
						onClick="doCancel(this.form);" /> 
				<input	type="submit" name="saveButton" class="inputButton"
						value="<bean:message bundle="em" key="button.save"/>" />
			</div>
			
	</html:form>
	</td>
</tr>
</table>
